package com.dot.dominion.view;

import java.lang.reflect.Field;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.dot.dominion.R;
import com.dot.dominion.domain.Card;

public class ImageAdapter extends BaseAdapter {
	private Integer[] mThumbIds;
	private Context mContext;
	private int area;
	
	public ImageAdapter( Context c, Card[] cardList ) {
		this( c, cardList, 115 );
	}
	
	public ImageAdapter( Context c, int[] pictureList ) {
		this( c, pictureList, 115 );
	}
	
	public ImageAdapter( Context c, int[] pictureList, int sArea ) {
		mContext = c;
		mThumbIds = new Integer[pictureList.length];
		area = sArea;
		
		for( int i = 0; i < pictureList.length; i++ )
			mThumbIds[i] = pictureList[i];
	}
	
	public ImageAdapter( Context c, Card[] cardList, int sArea ) {
		mContext = c;
		mThumbIds = new Integer[cardList.length];
		area = sArea;
		
		
		for( int i = 0; i < cardList.length; i++ ) {
			Card card = cardList[i];
			if( card != null )
				mThumbIds[i] = new Integer( card.getPictureId() );
			else
				mThumbIds[i] = 0;
		}
	}
	
	public int getCount() {
		return mThumbIds.length;
	}
	
	public Object getItem(int position) {
		return null;
	}
	
	public long getItemId(int position) {
		return mThumbIds[position];
	}
	
	public View getView(int position, View convertView, ViewGroup parent ) {
		ImageView imageView;
		
		if( convertView == null ) {
			imageView = new ImageView( mContext );
			
            imageView.setLayoutParams(new GridView.LayoutParams((area*7/10), area));
            imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            //imageView.setPadding(3, 3, 3, 3);
		}
		else
			imageView = (ImageView) convertView;
		
		imageView.setImageResource(mThumbIds[position]);
		
		return imageView;
	}
}
